package org.example.service.impl;

import org.example.mapper.UserMapper;
import org.example.model.User;
import org.example.service.UserService;
import org.example.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findByUserName(String username) {
        User user = userMapper.findByUserName(username);
        return user;
    }

    @Override
    public void rigister(String username, String password) {
        // 密码加密
        password = Md5Util.getMD5String(password);
        userMapper.add(username, password);

    }

    @Override
    public void update(User user) {
        userMapper.updata(user);
    }

    @Override
    public void updateAvatar(Number id, String avatarUrl, LocalDateTime updateTime) {
        userMapper.updateAvatar(id, avatarUrl, updateTime);
    }

    @Override
    public void updatePassword(Integer id, String newPassword, LocalDateTime updateTime) {
        userMapper.updatePassword(id, newPassword, updateTime);
    }
}
